﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


using LearnNet.Common;

using Advertise;
namespace Advertise
{
    public partial class FrmAdd : Form
    {
        public FrmAdd()
        {
            InitializeComponent();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            if (tbName.Text == "")
            {
                MessageBox.Show("请填写名称");
                return;
            }
            if (tbPwd.Text == "")
            {
                MessageBox.Show("请填写密码");
                return;
            }
            if (tbType.Text == "")
            {
                MessageBox.Show("请填写类型");
                return;
            }
            int count = 0;
            try
            {
                string str = string.Empty;
                str = "select count(*) from UserInfo where name='" + tbName.Text + "' and website='" + tbType.Text+ "'";
                count = Utils.StringToInt(LearnNet.DAL.DALHelper.LearnNetHelper.ExecuteScalar(CommandType.Text, str, null), 0);

                if (count > 0)
                {
                    MessageBox.Show("已经添加过该数据");
                    return;

                }
                str = string.Concat("insert into UserInfo(name,pwd,website,email) values('", tbName.Text, "','", tbPwd.Text, "','", tbType.Text, "','"+tbEmail.Text+"')");

                LearnNet.DAL.DALHelper.LearnNetHelper.ExecuteNonQuery(CommandType.Text, str, null);
                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                
            }
        }

        private void tbName_Click(object sender, EventArgs e)
        {
            tbName.SelectAll();
            //tbName.Copy();
        }

        private void tbPwd_Click(object sender, EventArgs e)
        {
            tbPwd.SelectAll();
            //tbPwd.Copy();
        }

        private void tbType_Click(object sender, EventArgs e)
        {
            tbType.SelectAll();
        }

        private void tbEmail_Click(object sender, EventArgs e)
        {
            tbEmail.SelectAll();
        }

    }
}
